<template>
  <u-popup :show="show">
    <view class="popup-wrap">
      <view class="popup-header">
        <view class="popup-header__cancel" @click="handleClose">取消</view>
        <view class="popup-header__title">选择要发送的简历</view>
        <view class="popup-header__confirm" @click="handleConfirm">确认</view>
      </view>
      <view class="popup-body">
        <radio-group class="resume-list" @change="radioChange">
          <label class="resume-list-item" v-for="(item, index) in resumeList" :key="item.url">
            <view class="resume-list-item__left">
              <image class="resumeIcon" v-if="item.fileExtension === 'docx'"
                src="https://xingangtong.oss-cn-beijing.aliyuncs.com/common/docx%402x.png" mode="asspectFill" />
              <image class="resumeIcon" v-if="item.fileExtension === 'doc'"
                src="https://xingangtong.oss-cn-beijing.aliyuncs.com/common/doc%402x.png" mode="asspectFill" />
              <image class="resumeIcon" v-if="item.fileExtension === 'pdf'"
                src="https://xingangtong.oss-cn-beijing.aliyuncs.com/common/Pdf%402x.png" mode="asspectFill" />
              <view class="resume-wrap">


                <view class="resume-name">{{ item.name }}</view>
                <view class="resume-info">
                  <view class="resume-size">{{ item.size }}M</view>
                  <view class="resume-time">{{ item.updateTime }}</view>
                </view>
              </view>
            </view>
            <radio class="resume-list-item__radio" :value="index" :checked="index === resumeIndex" />
          </label>
        </radio-group>
      </view>
    </view>
  </u-popup>
</template>
<script>
import { showToast } from "../utils/common";

export default {
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    resumeList: {
      type: Array,
      default: () => ([])
    },
  },
  data() {
    return {
      resumeIndex: '',
    }
  },
  methods: {
    radioChange(e) {
      this.resumeIndex = Number(e.detail.value);
    },
    handleClose() {
      this.resumeIndex = '';
      this.$emit('close');
    },
    handleConfirm() {
      if (this.resumeIndex === '') {
        showToast('请选择简历')
        return
      }
      this.$emit('confirm', this.resumeList[this.resumeIndex]);
      this.resumeIndex = '';
    }
  }
}
</script>
<style lang="scss">
.resumeIcon {
  width: 85upx;
  height: 100upx;
}

.popup-wrap {
  background: #f7f7f7;

  .popup-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 15px 10px;
    background: #fff;

    .popup-header__cancel {
      font-size: 15px;
      color: #888888;
      line-height: 24px;
      padding: 0 5px;
    }

    .popup-header__title {
      flex: 1;
      width: 0;
      text-align: center;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      font-weight: 700;
      font-size: 16px;
      color: #333333;
      line-height: 25px;
    }

    .popup-header__confirm {
      font-size: 15px;
      color: #37AF71;
      line-height: 24px;
      padding: 0 5px;
    }
  }

  .popup-body {
    padding: 10px;

    .resume-list {
      width: 100%;
      display: block;
    }

    .resume-list-item {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 12px 20px;
      background: #fff;
      border-radius: 4px;
      margin-bottom: 10px;

      &:last-child {
        margin-bottom: 0;
      }

      .resume-list-item__left {
        flex: 1;
        width: 0;
        display: flex;
        align-items: center;
        gap: 16px;

        .file-type {
          width: 42.5px;
          height: 50px;
          border: 1px solid #eee;
        }

        .resume-wrap {
          flex: 1;
          width: 0;

          .resume-name {
            font-weight: 500;
            font-size: 14px;
            color: #333333;
          }

          .resume-info {
            display: flex;
            align-items: center;
            margin-top: 6px;
            gap: 8px;
            font-size: 12px;
            color: #666666;
            line-height: 22px;
          }
        }
      }

      .resume-list-item__radio {
        transform: scale(0.9);
      }
    }
  }
}
</style>
